package cn.zhoujing.security.demo.controller;

import cn.zhoujing.security.demo.common.api.CommonResult;
import cn.zhoujing.security.demo.dto.LoginDTO;
import cn.zhoujing.security.demo.entity.User;
import cn.zhoujing.security.demo.service.UserService;
import cn.zhoujing.security.demo.vo.AccessToken;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping(value = "/test")
    @ResponseBody
    public String test() {
        List<User> list = userService.list();
        return list.toString();
    }

    @PostMapping(value = "/login")
    public CommonResult<AccessToken> login(@RequestBody @Validated LoginDTO dto) {
        AccessToken accessToken = userService.login(dto);
        return CommonResult.success(accessToken);
    }

    @GetMapping(value = "/list")
    public CommonResult<String> list() {
        return CommonResult.success("USER_LIST");
    }

}
